﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.复习九月份
{
    public class Solution718
    {
        public int FindLength(int[] nums1, int[] nums2)
        {
            int m = nums1.Length; int n = nums2.Length;

            int[][] dp = new int[m + 1][];
            int res = 0;
            for (int i = 0; i <= m; i++)
            {
                dp[i] = new int[n + 1];
            }
            for (int i = 1; i <= m; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    if (nums1[i - 1] == nums2[j - 1])
                    {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                        Console.WriteLine("dp[i][j]:  " + dp[i][j] + "  i:  " + i + "  j:  " + j);
                    }

                    res = Math.Max(dp[i][j], res);
                }
            }
            return res;
        }
    }

    internal class Program718
    {
        private static void Main718(string[] args)
        {
            int[] nums1 = [1, 2, 3, 2, 1], nums2 = [3, 2, 1, 4, 7];
            Solution718 solution = new Solution718();
            int res = solution.FindLength(nums1, nums2);
            Console.WriteLine(res);
        }
    }
}